package cn.demo.um.support.handler.base;

import cn.demo.um.domain.UmAttrData;
import cn.demo.um.service.IUmAttrDataService;
import cn.demo.um.support.handler.MatcherContext;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.List;
import java.util.Map;

/**
 * 单属性匹配处理器
 * 目前无用
 */
@Component
@Slf4j
public class SingleBaseMatcherHandler implements IBaseMatcherHandler {
    @Autowired
    private IUmAttrDataService umAttrDataService;

    @Override
    public void handler(MatcherContext matcherContext, String attrCode, double score) {
        List<String> factors = matcherContext.getFactor(attrCode);
        List<String> list = umAttrDataService.queryChain()
                .eq(UmAttrData::getAttrCode, attrCode)
                .eq(UmAttrData::getIsStandard, 0)
                .eq(UmAttrData::getAttrValue, factors.getFirst())
                .listAs(String.class);
        log.info("---------{}为【{}】的人数有---------", attrCode, list.size());
        matcherContext.addMatchScopeAttr(list, score,attrCode);
    }

    @Override
    public Map<String, List<String>> buildInvertedIndex(List<UmAttrData> umAttrDataList, String attrCode) {
        return null;
    }
}
